import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
import { Dict } from './dict.entity';
import { TimeTransformer } from 'src/utils/TimeTransformer.util';

/**
 * 字典数据实体
 */
@Entity('sys_dict_data')
export class DictData {
  /**
   * 字典数据ID
   */
  @PrimaryGeneratedColumn({ comment: '字典数据ID' })
  dictDataId: number;

  /**
   * 字典ID
   */
  @Column({ comment: '字典ID' })
  dictId: number;

  /**
   * 字典类型
   */
  @Column({ comment: '字典类型', length: 50 })
  type: string;

  /**
   * 字典标签
   */
  @Column({ comment: '字典标签', length: 100 })
  label: string;

  /**
   * 字典键值
   */
  @Column({ comment: '字典键值', length: 100 })
  value: string;

  /**
   * 状态
   */
  @Column({ comment: '状态', default: true })
  status: boolean;

  /**
   * 排序
   */
  @Column({ comment: '排序', default: 0 })
  orderNo: number;

  /**
   * 备注
   */
  @Column({ comment: '备注', nullable: true, length: 255 })
  remark: string;

  /**
   * 创建时间
   */
  @CreateDateColumn({
    comment: '创建时间',
    transformer: TimeTransformer,
  })
  createTime: Date;

  /**
   * 更新时间
   */
  @UpdateDateColumn({
    comment: '更新时间',
    transformer: TimeTransformer,
  })
  updateTime: Date;

  /**
   * 关联的字典
   */
  @ManyToOne(() => Dict, (dict) => dict.dictDatas)
  @JoinColumn({ name: 'dictId' })
  dict: Dict;
}
